package com.secsbrain.engine.web.controller;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.activiti.engine.task.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.*;

import com.secsbrain.engine.client.model.ExampleDto;

import java.util.List;

@RestController
@RequestMapping("api")
@EnableEurekaClient
public class AppController {
	
    private static final Logger logger = LoggerFactory.getLogger(AppController.class);

    //@Resource
    //private IIdUserService idUserService;
    
    @Value("${server.port}")
	String port;
    
    @RequestMapping("/hi")
	public ExampleDto home(@RequestParam String name) {
		System.out.println(111122222);
		return new ExampleDto(name, port);
	}
    
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public void test() {
    	ProcessEngine processEngine=ProcessEngines.getDefaultProcessEngine();
    	TaskService taskService=processEngine.getTaskService();
    	
    	RepositoryService repositoryService=processEngine.getRepositoryService();
    	RuntimeService runtimeService=processEngine.getRuntimeService();
    	HistoryService historyService=processEngine.getHistoryService();
    	
    	List<Task> sss=taskService.createTaskQuery()
    			.processInstanceId("27508").list();
    	
    	System.out.println(sss);
    	
    	ManagementService managementService=processEngine.getManagementService();
    	
    }
    
    @RequestMapping(value = "/generate", method = RequestMethod.GET)
    public void generate(){
    	try {
    		ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
    		        .setJdbcUrl("jdbc:mysql://172.16.189.131:3311/engine").setJdbcUsername("engine_all")
    		        .setJdbcPassword("pi54l2n4k523n2j4")
    		        .setJdbcDriver("com.mysql.jdbc.Driver")
    		        .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
    		// 获取流程引擎对象
    		ProcessEngine processEngine = cfg.buildProcessEngine();
		} catch (Exception e) {
			logger.error("",e);
		}
    	
    }
    
}
